home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Windows files / Q3WinSDK.exe / QD3DSDK / Samples / ViewerSampleWin32Only / 3DShell.c next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  5.4 KB  |  215 lines

  1. #include <windows.h>        // required for all Windows applications
  2. #include "resource.h"        // Windows resource IDs
  3. #include "3dshell.h"        // specific to this program
  4.  
  5. #include <stdio.h>
  6. #include "QD3DWinViewer.h"
  7.  
  8. HINSTANCE hInst;              // current instance
  9. HWND gHwnd;                    // main hwnd
  10.  
  11. HWND        gViewer;
  12.  
  13. char szAppName[] = "QuickDraw 3D Viewer Demo";        // The name of this application
  14. char szTitle[]   = "QuickDraw 3D Viewer Demo";        // The title bar text
  15.  
  16. /* define NOLINKVIEWER if you want to dynamically link to 3DViewer.LIB */
  17. #if defined (NOLINKVIEWER) 
  18.  
  19. #if defined( _DEBUG )
  20. #define VIEWERDLL "3DViewer_D.DLL"
  21. #else
  22. #define VIEWERDLL "3DViewer.DLL"
  23. #endif 
  24.  
  25. #endif /* NOLINKVIEWER */
  26.  
  27. int CALLBACK WinMain(
  28.         HINSTANCE hInstance,
  29.         HINSTANCE hPrevInstance,
  30.         LPSTR lpCmdLine,
  31.         int nCmdShow)
  32. {
  33.  
  34.         MSG msg;
  35.         HANDLE hAccelTable;
  36.         BOOL aStatus = FALSE;
  37.  
  38. #if !defined (NOLINKVIEWER) /* dummy call to Q3Viewer to force link */
  39.         Q3WinViewerGetState( NULL );
  40. #endif /* !NOLINKVIEWER */
  41.  
  42.         
  43.         if (!InitApplication(hInstance)) 
  44.         {
  45.             return (FALSE);    
  46.         }
  47.  
  48.         if (!InitInstance(hInstance, nCmdShow)) 
  49.         {
  50.             return (FALSE);
  51.         }
  52.  
  53.         hAccelTable = LoadAccelerators (hInstance, MAKEINTRESOURCE(IDR_GENERIC));
  54.         
  55.         (void) InvalidateRect(gHwnd, NULL, FALSE);    
  56.  
  57.         while (GetMessage(&msg, NULL, 0, 0)) {
  58.             if (!TranslateAccelerator (gHwnd, hAccelTable, &msg)) {
  59.                 TranslateMessage(&msg);
  60.                 DispatchMessage(&msg);
  61.             }
  62.         }
  63.  
  64.         return (msg.wParam); // Returns the value from PostQuitMessage
  65. }
  66.  
  67.  
  68. BOOL InitApplication(HINSTANCE hInstance)
  69. {
  70.     WNDCLASS  wc;
  71.     ATOM      success;
  72.     
  73.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  74.     wc.lpfnWndProc   = (WNDPROC)WndProc;       
  75.     wc.cbClsExtra    = 0;                      
  76.     wc.cbWndExtra    = 0;                     
  77.     wc.hInstance     = hInstance;             
  78.     wc.hIcon         = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APP)); 
  79.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  80.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  81.     wc.lpszMenuName  = MAKEINTRESOURCE(IDR_GENERIC); 
  82.     wc.lpszClassName = szAppName;              
  83.     
  84.     success = RegisterClass(&wc);
  85.  
  86.     return success > 0 ? TRUE : FALSE;
  87. }
  88.  
  89. BOOL InitInstance(
  90.         HINSTANCE       hInstance,
  91.         int             nCmdShow)
  92. {
  93.  
  94.     hInst = hInstance; 
  95.     gHwnd =  CreateWindowEx(
  96.         WS_EX_WINDOWEDGE|WS_EX_CLIENTEDGE,    // extended window style
  97.         szAppName,    // pointer to registered class name
  98.         szTitle,    // pointer to window name
  99.         WS_OVERLAPPED | WS_CAPTION |WS_THICKFRAME | WS_SYSMENU,    // window style
  100.         25, 25, 400, 450,      // fixed size windows
  101.         NULL,    // handle to parent or owner window
  102.         NULL,    // handle to menu, or child-window identifier
  103.         hInstance,    // handle to application instance
  104.         NULL     // pointer to window-creation data
  105.     );
  106.  
  107.     if (!gHwnd) 
  108.     {
  109.         return (FALSE);
  110.     }
  111.  
  112.  
  113.     ShowWindow(gHwnd, nCmdShow); 
  114.     UpdateWindow(gHwnd); 
  115.  
  116.     return( TRUE );
  117. }
  118.  
  119.  
  120. LRESULT CALLBACK WndProc(
  121.                 HWND hWnd,        
  122.                 UINT message,      
  123.                 WPARAM uParam,     
  124.                 LPARAM lParam)   
  125. {
  126.         int wmId, wmEvent;
  127.  
  128.         switch (message) 
  129.         {
  130.             case WM_COMMAND:
  131.  
  132.                 wmId    = LOWORD(uParam);
  133.                 wmEvent = HIWORD(uParam);
  134.  
  135.                 switch (wmId) 
  136.                 {
  137.                     case IDM_EXIT:
  138.                         DestroyWindow (hWnd);
  139.                         break;
  140.  
  141.                     default:
  142.                         return (DefWindowProc(hWnd, message, uParam, lParam));
  143.                 }
  144.                 break;
  145.  
  146.  
  147.             case WM_CREATE:
  148.                 {
  149.                 RECT rect;
  150.                 DWORD    dwFlags, flags;
  151. #if defined (NOLINKVIEWER) /* not linked with 3DViewer.LIB */
  152.                 HMODULE hDll;
  153. #endif 
  154.                 gViewer = NULL;
  155.                 
  156.                 flags = kQ3ViewerDefault;
  157.                 GetClientRect(hWnd, (LPRECT)&rect);
  158.  
  159.                 dwFlags = WS_VISIBLE;
  160.  
  161.                 if (!(flags & WS_POPUP))
  162.                     dwFlags |= WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  163.  
  164. #if defined (NOLINKVIEWER) /* we are not linked with 3DViewer.LIB; manually load library */
  165.                 if( hDll = LoadLibrary( VIEWERDLL ) )
  166.                     gViewer =  CreateWindowEx (
  167.                                 flags & kQ3ViewerDraggingInOff ? 0 : WS_EX_ACCEPTFILES , 
  168.                                 kQ3ViewerClassName, 
  169.                                 "My 3D Viewer", 
  170.                                 dwFlags | flags, 
  171.                                 rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
  172.                                 hWnd, 
  173.                                 NULL, 
  174.                                 hInst, 
  175.                                 NULL);
  176. #else  /* linked with 3DViewer.LIB */
  177.                 gViewer =  CreateWindowEx (
  178.                             flags & kQ3ViewerDraggingInOff ? 0 : WS_EX_ACCEPTFILES , 
  179.                             kQ3ViewerClassName,        /* this is the only symbol in 3DViewer we link against */
  180.                             "My 3D Viewer", 
  181.                             dwFlags | flags, 
  182.                             rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
  183.                             hWnd, 
  184.                             NULL, 
  185.                             hInst, 
  186.                             NULL);
  187. #endif 
  188.                 if( gViewer == NULL )
  189.                     return -1;
  190.                 }
  191.                 break;
  192.  
  193.             case WM_DESTROY:  // message: window being destroyed
  194.                 PostQuitMessage(0);
  195.                 break;
  196.  
  197.             case WM_SETFOCUS:
  198.                 SetFocus( gViewer );
  199.                 break;
  200.  
  201.             case WM_SYSCOLORCHANGE:
  202.                 SendMessage (gViewer , WM_SYSCOLORCHANGE, 0 , 0);
  203.                 break;
  204.  
  205.             default:          // Passes it on if unproccessed
  206.                     return (DefWindowProc(hWnd, message, uParam, lParam));
  207.         }
  208.         return (0);
  209. }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.